home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / colorlab / modmisc.bas < prev    next >
BASIC Source File  |  1999-09-24  |  1KB  |  34 lines

  1. Attribute VB_Name = "modMisc"
  2. Option Explicit
  3.  
  4. Public Function ZHex(lHex As Long, iZeros As Integer) As String
  5. 'returns a HEX string of specified length (pad zeros on left)
  6.     ZHex = Right$(String$(iZeros - 1, "0") & Hex$(lHex), iZeros)
  7. End Function
  8.  
  9. Public Function UtoH(U As String) As String
  10. 'takes the Unicode string of custom colors and converts it to hex codes
  11. 'that can be easily saved
  12. Dim i As Integer, strHex As String, strH As String
  13.     For i = 1 To Len(U)
  14.         strH = ZHex(AscW(Mid$(U, i, 1)), 4)
  15.         strHex = strHex & strH
  16.     Next i
  17.     UtoH = strHex
  18. End Function
  19.  
  20. Public Sub HtoU(strHex As String)
  21. 'Takes the hex string and loads the custom colors
  22. Dim i As Integer, strU As String
  23. Dim customcolors() As Byte  ' dynamic (resizable) array
  24.     If strHex = "" Then ColorDialog.lpCustColors = "": Exit Sub
  25.     
  26.     ReDim customcolors(0 To (Len(strHex) / 4)) As Byte  'resize the array
  27.     
  28.     For i = 3 To Len(strHex) - 1 Step 4
  29.         customcolors((i - 3) / 4) = Val("&H" & Mid$(strHex, i, 2))
  30.     Next i
  31.     ColorDialog.lpCustColors = StrConv(customcolors, vbUnicode)  ' convert array
  32. End Sub
  33.  
  34.